
;(function (RCABase) {
    var index;
    var peopleOptions;
    var table_records_pro = $('#table_records_pro');
    $table = $("#table").bootstrapTable(peopleOptions);
    var init={
        extend: {
            ajax_url: '/admin/Aftersale/ajax',
            weibaofinish_url: '/admin/Service/weibaofinish',
            sex_1:'男',
            sex_2:'女',

        },
        lookLayerImg:function(img) {
            layer.photos({
                photos: {
                    "title": "", //相册标题
                    "id": 'image_preview', //相册id
                    "start": 0, //初始显示的图片序号，默认0
                    "data": [   //相册包含的图片，数组格式
                        {
                            "alt": "",
                            "pid": 666, //图片id
                            "src": img, //原图地址
                            "thumb": img //缩略图地址
                        }
                    ]
                } //格式见API文档手册页
                , anim: 5, //0-6的选择，指定弹出图片动画类型，默认随机
                shadeClose: true,
                // skin: 'layui-layer-nobg',
                shade: [0.5, '#000000'],
                shadeClose: true,
            })
        },
        totalConventionalFund:function(){
            var totalSou = 0;
            $('.conventional tr').each(function (i,n) { 
                var t = (init.getNumValue($(this).find("td:eq(3) input")) -
                    init.getNumValue($(this).find("td:eq(8) input")));
                $(this).find("td:eq(9) input").val(t)
                $(this).find("td:eq(9) label").text(t)

                if ($(this).find(" td:eq(0) input").is(':checked')){
                    $(this).find("td:eq(9) input").each(function () {
                        totalSou += init.getNumValue($(this)) ;
                        console.log(totalSou);
                        $('#conventional_total_price_font').text('合计金额：'+ Number(totalSou.toFixed(2)));
                        $('#conventional_total_price').val(Number(totalSou.toFixed(2)));
                    });
                } 
            })
        },
        totalStoneFund:function(){
            var totalSou = 0;
            $('.stone tr').each(function (i, n) {
               var t = (init.getNumValue($(this).find("td:eq(3) input"))*
                   init.getNumValue($(this).find("td:eq(4) input")))-
                   init.getNumValue($(this).find("td:eq(10) input"));
                if ($(this).find("td:eq(9) input").is(":checked")){
                    console.log(232)
                    $(this).find("td:eq(11) input").val(0)
                    $(this).find("td:eq(11) label").text(0)
                }else {
                    $(this).find("td:eq(11) input").val(t)
                    $(this).find("td:eq(11) label").text(t)
                }
                if ($(this).find(" td:eq(0) input").is(':checked')) {
                    $(this).find("td:eq(11) input").each(function () {
                        totalSou += init.getNumValue($(this));
                        $('#stone_total_price_font').text('合计金额：' + Number(totalSou.toFixed(2)));
                        $('#stone_total_price').val( Number(totalSou.toFixed(2)));
                    });
                }
            })
        },
        totalMbFund:function () {

        },
        getNumValue:function(controlid) {
            var num = controlid.val();
            if (init.validateInput(num)) {
                num = parseFloat(num);
            } else {
                controlid.val("");
                num = 0;
            }
            return num;
        },
        validateInput:function (inputstr) {
            var flag = false;
            if (inputstr != "") {
                if (isNaN(inputstr)) {
                     flag = false; //如果输入字符不是数字
                }else {
                    //输入数字但是小于0
                   if (parseFloat(inputstr) < 0)
                      flag = false;
                   else
                       flag = true;
                }
            }
            return flag;
        },
        recordsList:function () {
            $('#table_records').bootstrapTable({
                url: init.extend.ajax_url+"?t=1",
                pageNumber: 1, //初始化加载第一页
                pagination: true,//是否分页
                sidePagination: 'server',//server:服务器端分页|client：前端分页
                pageSize: 10,//单页记录数
                pageList: [5, 10, 20],//可选择单页记录数
                showRefresh: false,//刷新按钮
                showColumns: false, //
                columns: [
                    {checkbox:true},
                    {field: 'no', title: '序号', formatter: function (value, row, index) {
                            //获取每页显示的数量
                            var pageSize = $('#table_records' ).bootstrapTable('getOptions').pageSize;
                            //获取当前是第几页
                            var pageNumber = $('#table_records').bootstrapTable('getOptions').pageNumber;
                            //返回序号，注意index是从0开始的，所以要加上1
                            return pageSize * (pageNumber - 1) + index + 1;}},
                    {field: 'register_time', title: '登记时间'},
                    {field: 'business_num', title: '业务编号'},
                    {field: 'business_type', title: '业务类型'},
                    {field: 'type', title: '业务内容',  events: "operateEventswb",formatter: function (value, row, index) {
                            return ' <a href="javascript:"  class="RoleOfA_ls">点击查看</a>'}},
                    {field: 'tomb_num', title: '墓位编号'},
                    {field: 'tomb_address', title: '具体位置'},
                    {field: 'handle_name', title: '经办人'},
                    {field: 'service_status', title: '状态',formatter: function (value, row, index) {
                            if (value == 1) return '未确认'; else if (value == 2) return '已确认'; else if (value == 3) return '已确认';
                            else if (value == 4) return '已上传'; else return '';}}
                ],
                queryParams: function (params) {
                    //上传服务器的参数
                    var temp = {
                        page: params.offset + 0,// SQL语句起始索引
                        limit: params.limit  // 每页显示数量
                    };
                    return temp;
                },
                formatLoadingMessage: function () {
                    return "数据正在加载中...";
                },
                formatNoMatches: function () {
                    return '无符合条件的记录';
                },
            });
        },
        recordsInfolookAt:function (url,id) {
            table_records_pro.bootstrapTable({
                // url: url,
                // method:'get',
                // cache: false,
                striped: true,
                pageNumber: 1, //初始化加载第一页
                pagination: true,//是否分页
                sidePagination: 'server',//server:服务器端分页|client：前端分页
                pageSize: 10,//单页记录数
                pageList: [5, 10, 20],//可选择单页记录数
                showRefresh: false,//刷新按钮
                showColumns: false, //
                columns: [
                    {field: 'part_name', title: '项目名称'},
                    {field: 'warranty_type', title: '处理方式', },
                    {field: 'unit', title: '单位'},
                    {field: 'part_price', title: '单价'}
                ],
                queryParams: function (params) {
                    //上传服务器的参数
                    var temp = {
                        page: params.offset + 0,// SQL语句起始索引
                        limit: params.limit  // 每页显示数量
                    };
                    return temp;
                },
                formatLoadingMessage: function () {
                    return "数据正在加载中...";
                },
                formatNoMatches: function () {
                    return '无符合条件的记录';
                },
            });
        },
        AjaxRecordsInfolookAt:function (t,href,callback) {
            $.getJSON(href).done(function (returnValue) {
                    var arr = returnValue.data,
                        html='',
                        thead='',status_name = '',
                        sum_total_price=0,
                        tbody='';

                    if (t==1) {
                        thead += '<tr><th width="20"><input type="checkbox" style="width: 20px;" class="js-check-all"  /></th>\n' +
                            ' <th>序号</th><th>项目名称</th><th>单位</th><th>单价</th><th >费用减免</th><th >实收金额</th>' +
                            ' <th >质保</th><th >加急</th><th >交付时间</th><th >维修部门</th></tr>';
                        $.each(arr, function (i, n) {
                            var checked = '', part_price = n.part_price, total_price = n.total_price,
                                warranty_type = '维修', warranty = '无';
                            if (total_price == 0) {
                                warranty_type= '更换';
                            }
                            if (total_price == 0) {
                                total_price = '免费';
                            }
                            if (n.part_price == 0) {
                                part_price = '免费';
                            }
                            if (n.warranty != 0) {
                                warranty = n.warranty + '年';
                            }
                            if (n.expedited == 1) {
                                checked = 'checked';
                            }
                            tbody += '<tr><td width="20"><input type="checkbox" style="width: 20px;" class=" "  /></td>\n' +
                                '  <td>' + (i + 1) + '</td><td>' + n.part_name + '</td>\n' +
                                '  <td>' + n.unit + '</td>\n' +
                                '  <td>' + part_price + '</td>\n' +
                                '  <td>' + n.fee_reduction + '</td> <td>' + total_price + '</td>\n' +
                                '  <td>' + warranty + '</td><td><input type="checkbox" class="js-check-all" ' + checked + ' /></td>\n' +
                                '  <td>' + n.deliver_time + '</td><td>' + n.department_name+'-'+n.user_nickname + '</td>\n' +
                                '</tr>';
                            console.log(n.total_price);
                            if (n.total_price!=0){
                                sum_total_price += parseFloat(n.total_price);
                            }
                        });

                    } else if (t==2) {
                        thead += '<tr><th width="20"><input type="checkbox" style="width: 20px;" class="js-check-all"  /></th>\n' +
                            ' <th>序号</th><th>项目名称</th><th>处理方式</th><th>单位</th><th>单价</th><th>数量</th><th >费用减免</th><th >实收金额</th>' +
                            ' <th >质保</th><th >加急</th><th >交付时间</th><th >维修部门</th></tr>';
                        $.each(arr, function (i, josn) {
                            var checked = '', part_price = josn.part_price, total_price = josn.total_price,free_warranty = josn.free_warranty,
                                warranty_type = '维修', warranty = '无';
                            if (total_price == 0) {
                                warranty_type= '更换';
                            }
                            if (free_warranty == 0) {
                                free_warranty = '免费';
                            }
                            if (total_price == 0) {
                                total_price = '免费';
                            }
                            if (josn.part_price == 0) {
                                part_price = '免费';
                            }
                            if (josn.warranty != 0) {
                                warranty = josn.warranty + '年';
                            }
                            if (josn.expedited == 1) {
                                checked = 'checked';
                            }
                            tbody += '<tr><td w><input type="checkbox" style="width: 20px;" class=" "  /></td>\n' +
                                '  <td>' + (i + 1) + '</td><td>' + josn.part_name + '</td>\n' +
                                '  <td>' + warranty_type + '</td><td>' + josn.unit + '</td>\n' +
                                '  <td>' + part_price + '</td><td>' + josn.duration + '</td>\n' +
                                '  <td>' + free_warranty + '</td> <td>' + total_price + '</td>\n' +
                                '  <td>' + warranty + '</td><td><input type="checkbox" class="js-check-all" ' + checked + ' /></td>\n' +
                                '  <td>' + josn.deliver_time + '</td><td>' + josn.dept_id + '</td>\n' +
                                '</tr>';
                            console.log(josn.total_price);
                            if (josn.total_price!=0){
                                sum_total_price += parseFloat(josn.total_price);
                            }
                        });
                    } else if (t==3) {
                        thead += '<tr><th width="20"><input type="checkbox" style="width: 20px;" class="js-check-all"  /></th>\n' +
                            ' <th>序号</th><th>项目名称</th><th>新碑型号</th><th>单位</th><th>单价</th><th>数量</th><th >费用减免</th><th >实收金额</th>' +
                            ' <th >质保</th><th >加急</th><th >交付时间</th><th >维修部门</th><th >查看维修结果</th></tr>';

                        $.each(arr, function (i, josn) {
                            var checked = '', part_price = josn.part_price, total_price = josn.total_price,free_warranty = josn.fee_reduction,
                                warranty_type = '维修', warranty = '无';
                            if (total_price == 0) {
                                warranty_type= '更换';
                            }
                            if (free_warranty == 0) {
                                free_warranty = '0';
                            }
                            if (total_price == 0) {
                                total_price = '免费';
                            }
                            if (josn.part_price == 0) {
                                part_price = '免费';
                            }
                            if (josn.warranty != 0) {
                                warranty = josn.warranty + '年';
                            }
                            if (josn.expedited == 1) {
                                checked = 'checked';
                            }
                            tbody += '<tr><td w><input type="checkbox" style="width: 20px;" class=" "  /></td>\n' +
                                '  <td>' + (i + 1) + '</td><td>' + josn.part_name + '</td>\n' +
                                '  <td>' + josn.pro_name  + '</td> <td>' + josn.unit  + '</td>\n' +
                                '  <td>' + part_price + '</td><td>' + josn.duration + '</td>\n' +
                                '  <td>' + free_warranty + '</td> <td>' + total_price + '</td>\n' +
                                '  <td>' + warranty + '</td><td><input type="checkbox" class="js-check-all" ' + checked + ' /></td>\n' +
                                '  <td>' + josn.deliver_time + '</td><td>' + josn.dept_id + '</td>\n' +
                                '  <td><a href="javascript:;" class="details" data-title="'+josn.part_name+'" data-url="?ajax=1&TaskType=weibao&id='+josn.wb_id+'">点击查看</a></td>\n' +
                                '</tr>';
                            console.log(josn.total_price);
                            if (josn.total_price!=0){
                                sum_total_price += parseFloat(josn.total_price);
                            }
                        });
                    }
                    console.log(sum_total_price)
            tbody+=' <tr><td colspan="15"><font color="red" size="+2">历史交费：'+sum_total_price+' </font></td></tr>'
                html +=  ' <div class="control-group1-p" style="adding-top:20px;margin:0 20px;overflow:hidden; overflow-x:auto;">\n' +
                '   <form action="" method="post">\n' +
                '<table class="table table-hover table-bordered" >' +
                '   <thead>'+thead+'</thead><tbody>'+tbody+'</tbody></table>' +
                '</form>' +
                '</div>' ;
                callback(html);
            });
        },
        ajaxHandleInfolookAt:function(t,href,callback){
            //办理人信息
            $.getJSON(href).done(function (returnValue) {
                var arr = returnValue.data,
                    html='',thead='',tbody='';
                thead += '<tr><th width="20"><input type="checkbox" style="width: 20px;" class="js-check-all"  /></th>\n' +
                    '<th>登记时间</th><th>业务编号</th> <th>业务类型</th><th>业务内容</th><th >墓位编号</th><th >具体位置</th><th >经办人</th><th >状态</th>';
                $.each(arr, function (i, josn) {
                    tbody += '<tr><td w><input type="checkbox" style="width: 20px;" class=" "  /></td>\n' +
                        '   <td>' + josn.register_time + '</td><td>' + josn.business_num + '</td><td>' + josn.business_type + '</td> ' +
                        '   <td><a href="javascript:"   class="RoleOfA" data-title="'+ josn.department_name+'-'+josn.user_nickname+'" data-url="?t=2&id='+josn.id+'" data-type="'+josn.type+'">点击查看</a></td>\n' +
                        '   <td>' + josn.tomb_num + '</td><td>' + josn.tomb_address + '</td><td>' + josn.handle_name + '</td><td>' + josn.service_status + '</td>\n' +
                        '</tr>';
                });
                html +=  ' <div class="control-group1-p" style="adding-top:20px;margin:0 20px;overflow:hidden; overflow-x:auto;">\n' +
                    '   <form action="" method="post">\n' +
                    '<table class="table table-hover table-bordered" >' +
                    '   <thead>'+thead+'</thead><tbody>'+tbody+'</tbody></table>' +
                    '</form>' +
                    '</div>' ;
                callback(html);
            })
        },
        ajaxCustomerInfolookAt:function(t,href,callback){
            //购买人信息
            $.getJSON(href).done(function (returnValue) {
                var arr = returnValue.data,
                    html='',thead='',tbody='';
                console.log(arr);
                $.each(arr, function (i, n) {
                    html += '<form class="form-horizontal result_form " action="">\n' +
                        '            <fieldset>\n' +
                        '                <div  class="control-group1-p result_dep" style="border:1px solid #e2e2e2; padding:20px 0 0 20px;">\n' +
                        '                    <div class="row"  style="margin-left: 0;margin-right: 0;">\n' +
                        '                        <div class="col-md-6">\n' +
                        '                            <div class="form-group">\n' +
                        '                                <label class="control-label">办理人姓名</label>\n' +
                        '                                <div class="col-lg-9">' +
                        '                                    <input type="text" class="form-control" name="buyer_name" value="'+n.buyer_name+'" disabled >\n' +
                        '                                </div>\n' +
                        '                            </div>\n' +
                        '                            <div class="form-group">\n' +
                        '                                <label class="control-label" >手机号码</label>\n' +
                        '                                <div class="col-lg-9">\n' +
                        '                                    <input type="text" class="form-control" name="buyer_phone"  disabled value="'+n.buyer_phone+'" >\n' +
                        '                                </div>\n' +
                        '                            </div>\n' +
                        '                            <div class="form-group">\n' +
                        '                                <label class="control-label">联系地址</label>\n' +
                        '                                <div class="col-lg-9">\n' +
                        '                                    <input type="text" class="form-control" name="customer_address" disabled value="'+n.customer_address+'"  >\n' +
                        '                                </div>\n' +
                        '                            </div>\n' +
                        '                            <div class="form-group">\n' +
                        '                                <label class="control-label">经办人</label>\n' +
                        '                                <div class="col-lg-9">\n' +
                        '                                    <input type="text" class="form-control" name="second_name js-date" disabled value="'+n.user_nickname+'" />\n' +
                        '                                </div>\n' +
                        '                            </div>\n' +
                        '                            <div class="form-group">\n' +
                        '                                <label class="control-label">证件查看</label>\n' +
                        '                                <div class="col-lg-9">\n' +
                        '                                   <a href="javascript:;" class="lookImgss" data-url="'+n.cart_upload+'"  >查看</a>\n' +
                        '                                </div>\n' +
                        '                            </div>\n' +
                        '                        </div>\n' +
                        '                        <div class="col-md-6">\n' +
                        '                            <div class="form-group">\n' +
                        '                                <label class="control-label">性别</label>\n' +
                        '                                <div class="col-lg-9">\n' +
                        '                                    <input type="text" class="form-control" name="cart_address" disabled value="'+n.buyer_sex+'" disabled  >\n' +
                        '                                </div>\n' +
                        '                            </div>\n' +
                        '                            <div class="form-group">\n' +
                        '                                <label class="control-label">证件类型</label>\n' +
                        '                                <div class="col-lg-9">\n' +
                        '                                    <input type="text" class="form-control total_price" name="total_price" disabled value="'+n.cart_type+'" placeholder="">\n' +
                        '                                </div>\n' +
                        '                            </div>\n' +
                        '                            <div class="form-group">\n' +
                        '                                <label class="control-label">身份证号</label>\n' +
                        '                                <div class="col-lg-9">\n' +
                        '                                    <input type="text" class="form-control" name="cart_num" disabled value="'+n.customer_account+'">\n' +
                        '                                </div>\n' +
                        '                            </div>\n' +
                        '                            <div class="form-group">\n' +
                        '                                <label class="control-label">经办时间</label>\n' +
                        '                                <div class="col-lg-9">\n' +
                        '                                    <input type="text" class="form-control"  name="second_phone"  value="'+n.add_time+'" disabled>\n' +
                        '                                </div>\n' +
                        '                            </div>\n' +
                        '                        </div>\n' +
                        '                    </div>\n' +
                        '                </div>\n' +
                        '            </fieldset>\n' +
                        '        </form>';

                    });
                callback(html);
            })
        },
        ajaxWB:function(){
        },
        ajaxLayerOpen:function (title,html) {
            layer.open({type: 1,icon:4,title:[title,'color:#383838;font-size:16px;'], anim: 2,area: ['1220px','540px'],content:html});
        }
    };
    init.totalConventionalFund(),
    init.totalStoneFund(),
    window.operateEventswb = {
        'click .RoleOfA_ls': function (e, value, row, index) {
            // 历史查看业务
            if (row.type==1){
                 init.AjaxRecordsInfolookAt(1,init.extend.ajax_url+"?t=2&mb=0&id="+row.id,function (html) {
                     init.ajaxLayerOpen('常规信息',html)
                 });
            }else if (row.type==2) {
                init.AjaxRecordsInfolookAt(2,init.extend.ajax_url+"?t=2&mb=0&id="+row.id,function (html) {
                    init.ajaxLayerOpen('石材维修信息',html)
                });
            }else if (row.type==3) {
                init.AjaxRecordsInfolookAt(3,init.extend.ajax_url+"?t=2&mb=1&id="+row.id,function (html) {
                    init.ajaxLayerOpen('换新信息',html)
                });
            }
        },
    };

    $('.shicaiweixiu').change(function () {
        var part_json = $(this).children('option:selected').data('part_json');
        var userlistjson = $(this).children('option:selected').data('userlistjson');
        var userlist ='';
        console.log(userlistjson)
        $.each(userlistjson, function (i, nu) {
            userlist += "<option value='" + nu.id + "' >" + nu.department_name +"-"+nu.user_nickname+ "</option>";
        });

        $('.stone').html('');
        var html_tr='';
        $.each(part_json, function (i, n) {
              html_tr+= ' <tr>\n' +
                '             <td width="20">\n' +
                '                 <input type="checkbox" class="js-check" data-direction="y"  id="part_id"name="part[{$key}][part_id]" value="{$info.id}" />\n' +
                '              </td>\n' +
                '              <td>'+n.iname+' <input type="hidden"   name="part['+i+'][part_name]"  value="'+n.iname+'"/>\n' +'</td>\n' +
                '              <td>件</td>\n' +
                '              <td>\n' +
                '                  <label style="font-weight: normal;" class="part_price">'+n.irepair_price+'</label>\n' +
                '                  <input type="hidden" class="part_price"   name="part['+i+'][part_price]"  value="'+n.irepair_price+'" />\n' +
                '                  <input type="hidden"   name="part['+i+'][unit]"  value="件" /></td>\n' +
                '              <td>\n' +
                '                  <input type="text"  class="form-control duration" style="width: 50px"  name="part['+i+'][duration]"  value="'+n.inumber+'" />\n' +
                '              </td>\n' +
                '              <td>\n' +
                '                  <select name="part['+i+'][warranty_type]"  style="max-width:  90px "   class="form-control warranty_type">\n' +
                '                       <option value="1" data-price="'+n.irepair_price+'" data-title="维修1年">维修</option>\n' +
                '                      <option value="3" data-price="'+n.ichange_price+'" data-title="更换3年">更换</option>\n' +
                '                  </select>\n' +
                '              </td>\n' +
                '              <td>\n' +
                '                  <label style="font-weight: normal;" class="warranty">1年</label>\n' +
                '                  <input type="hidden" class="warranty"   name="part['+i+'][warranty]"  value="1" /></td>\n' +
                '              </td>\n' +
                '              <td>\n' +
                '                  <input type="checkbox" class="expedited" value="1" name="part['+i+'][expedited]" />\n' +
                '              </td>\n' +
                '              <td>\n' +n.is_expired+'</td>\n' +
                '              <td><input type="checkbox" class="free_warranty"   name="part['+i+'][free_warranty]"'+n.is_expired_checked+' /></td>\n' +
                '              <td><input type="text" class="form-control fee_reduction" style="min-width: 100px;" name="part['+i+'][fee_reduction]"  /></td>\n' +
                '              <td>\n' +
                '                  <label style="font-weight: normal;" class="total_price">0</label>\n' +
                '                  <input type="hidden" class="total_price"   name="part['+i+'][total_price]"  value="0" />\n' +
                '              </td>\n' +
                '              <td><input type="text" class="form-control js-date_jd" style="min-width: 115px;" name="part['+i+'][deliver_time]"  autocomplete="off" /> </td>\n' +
                '              <td><select name="part['+i+'][dep_id]"  style="min-width: 120px;"  class="form-control">\n' +userlist+'</select></td>\n' +
                '              <td>'+n.admin_name+'</td>\n' +
                '              <td><a href="javascript:" class="lookAt" data-title="'+n.iname+'"\n' +
                '                     data-url="?t=5&type=2&id='+n.id+'">点击查看</a></td>\n' +
                '              <td><input type="text" class="form-control " style="min-width: 100px;" name="part['+i+'][remark]"  /></td>\n' +
                '          </tr>';
        })

        html_tr+=' <tr class="stone_tr">\n' +
        '              <td colspan="20" id="all_total_price "><font color="red" size="+2" id="stone_total_price_font">合计金额：0 </font>\n' +
        '                     <input type="hidden" id="stone_total_price"   name="total_price"  value="0" />\n' +
        '                      <input type="hidden" class="itype"   name="itype"  value="0" />\n' +
        '            </td></tr>';
        $('.stone').append(html_tr);

    })

    $(document).on('click','.js-date_jd',function () {
        var dateInput =$(this);
        if ($(this).length) {
            Wind.use('datePicker', function () {
                dateInput.datePicker({
                    time: false,
                });
            });
        }
    })

    //历史 查看维修结果
    $(document).on('click','.details',function () {
        var url = $(this).data('url'),
            title = $(this).data('title'),
            width = $(this).data('width'),
            height = $(this).data('height');

        console.log(url)
        init.ajaxLayerOpen(title, '')
        /*$.ajax({
            'url':init.extend.weibaofinish_url+url, 'type': 'get', success: function (json) {
                console.log(json)
                // layer.open({type: 1,icon:4,title:[title,'color:#383838;font-size:16px;'], anim: 2,area:
                //         ['1220px','540px'],content:json});

                // init.ajaxLayerOpen(title, json,width,height)
            }
        })*/
    })
    $(document).on('click','.lookImgss',function () {
        init.lookLayerImg($(this).data('url'))
    })
    $(document).on('click','.RoleOfA',function () {
        var url = $(this).data('url'),
            title = $(this).data('title'),
        type = $(this).data('type');
        init.AjaxRecordsInfolookAt(type,init.extend.ajax_url+url,function (html) {
            init.ajaxLayerOpen(title,html)
        });
    })
    $('.lookAt').click(function () {
        var url = $(this).data('url'),
            title = $(this).data('title');console.log(init.extend.ajax_url+url);
        init.ajaxHandleInfolookAt(1,init.extend.ajax_url+url,function (html) {
            init.ajaxLayerOpen(title,html)
        });
    });
    $('.lookCustomer').click(function () {
        var url = $(this).data('url'),
            title = $(this).data('title');console.log(init.extend.ajax_url+url);
        init.ajaxCustomerInfolookAt(1,init.extend.ajax_url+url,function (html) {
            init.ajaxLayerOpen(title,html)
        });
    });
    $(document).on('blur','.pro_mb',function () {
        var pro_price = $(this).children('option:selected').data('pro_price');
        if (pro_price==null) {
            pro_price = 0;
        }
        console.log(pro_price)
        var duration = $(this).parent().parent().find('.mb_duration').val();
        var fee_reduction = $(this).parent().parent().find('.fee_reduction').val();
        $(this).parent().parent().find('.part_price').val(pro_price);
        $(this).parent().parent().find('.part_price').text(pro_price);
        $(this).parent().parent().find('.total_price').val(pro_price*duration-fee_reduction);
        $(this).parent().parent().find('.total_price').text(pro_price*duration-fee_reduction);
        var total_price = $(this).parent().parent().find('.total_price').val();
        console.log(total_price)
        $('#mb').find('#mb_total_price_font').text('合计金额：' +total_price);
        $('#mb').find('#mb_total_price').val(total_price);
    })
    $(document).on('blur','.mb_duration',function () {
        var pro_price = $(this).parent().parent().find('.pro_mb').children('option:selected').data('pro_price');
        var fee_reduction = $(this).parent().parent().find('.fee_reduction').val();
        console.log(fee_reduction);
        var duration = $(this).val();
        $(this).parent().parent().find('.part_price').val(pro_price);
        $(this).parent().parent().find('.part_price').text(pro_price);
        $(this).parent().parent().find('.total_price').val(pro_price*duration-fee_reduction);
        $(this).parent().parent().find('.total_price').text(pro_price*duration-fee_reduction);
        var total_price = $(this).parent().parent().find('.total_price').val();
        console.log(total_price)
        $('#mb').find('#mb_total_price_font').text('合计金额：' + total_price);
        $('#mb').find('#mb_total_price').val(total_price);

    })

    $(document).on('blur','.fee_reduction',function () {
        var pro_price = $(this).parent().parent().find('.pro_mb').children('option:selected').data('pro_price');
        var duration = $(this).parent().parent().find('.mb_duration').val();
        var fee_reduction = $(this).val();
        // $(this).parent().parent().find('.part_price').val(pro_price);
        // $(this).parent().parent().find('.part_price').text(pro_price);
        $(this).parent().parent().find('.total_price').val(pro_price*duration-fee_reduction);
        $(this).parent().parent().find('.total_price').text(pro_price*duration-fee_reduction);
        var total_price = $(this).parent().parent().find('.total_price').val();
        console.log(total_price)
        $('#mb').find('#mb_total_price_font').text('合计金额：' + total_price);
        $('#mb').find('#mb_total_price').val(total_price);

    })
    //切换显示
    $(document).on('click','.nav_tabs li',function(){
        var k = $(this).data('index');
        $(this).addClass('active').siblings().removeClass('active');
        var index = $(".nav_tabs li").index(this);
        billtype = index;
        $('.content_nav').eq(index).removeClass("feature").siblings().addClass("feature");
        if (k==4){
            init.recordsList();
            $("#table_records").bootstrapTable('refresh', {url:init.extend.ajax_url+"?t=1"});
        }
    });
    $('.js-check-all').click(function (e) {
        var name = $(".js-check");
        var direction = $(this).data('direction');
        if($(this).is(':checked')){
            for(var i=0;i<name.length;i++){
                name[i].checked=true ;
                console.log((name))
                $('.'+direction).css("background", "#f7f7f7")
            }
        }else {
            for(var i=0;i<name.length;i++){
                name[i].checked=false ;
                $('.'+direction).css("background", "")
            }
        }
    });
    $(document).on('click','.js-check',function () {
        if ($(this).is(":checked")){
            $(this).parent().parent().css("background", "#f7f7f7");
        }else {
            $(this).parent().parent().css("background", "");
        }
        init.totalConventionalFund();
        init.totalStoneFund();
    })
    //维保数量
    $(document).on('blur','.duration',function () {
        init.totalConventionalFund();
        init.totalStoneFund();
    })
    //费用减免
    $(document).on('blur','.fee_reduction',function () {
        init.totalConventionalFund();
            init.totalStoneFund();
    })
    //质保免费
    $(document).on('click','.free_warranty',function () {
        if ($(this).is(":checked")){
            console.log(0)
        }else {
            init.totalStoneFund();
        }
    })
    $(document).on('change','.warranty_type',function () {
        var y= $(this).val();
        var price  = $(this).children('option:selected').data('price');
       $(this).parent().parent().children().eq(3).find('.part_price').val(price);
       $(this).parent().parent().children().eq(3).find('.part_price').text(price);
        $(this).parent().parent().children().eq(6).find('.warranty').text(y+'年');
       $(this).parent().parent().children().eq(6).find('.warranty').val(y);
        if (y==1){
          $(this).parent().parent().children().eq(9).find('.js-check-all').attr("checked",true);
        }else {
          $(this).parent().parent().children().eq(9).find('.js-check-all').attr("checked",false);
        }
        $(this).parent().parent().children().eq(11).find('.total_price').val(price);
        $(this).parent().parent().children().eq(11).find('.total_price').text(price);
        init.totalStoneFund();
    })
    $(document).on('click','#check-conventional',function (){
        $('#form_conventional').find('.itype').val(1)
        $.post($("#form_conventional").attr('action'), $("#form_conventional").serialize(), function(result){
            if(result.code == 1){
                layer.alert('提交成功。', {icon: 1, yes: function (index) {
                        layer.close(index);
                        window.location.href = result.url;
                    }})
            } else {
                layer.msg(result.msg);
            }
        }, 'json');
    })
    $(document).on('click','#check-conventional-btn',function () {
        $('#form_conventional').find('.itype').val(0)
        $.post($("#form_conventional").attr('action'), $("#form_conventional").serialize(), function(result){
            if(result.code == 1){
                layer.alert('提交成功。', {icon: 1, yes: function (index) {
                        layer.close(index);
                        window.location.href = result.url;
                    }})
            } else {
                layer.msg(result.msg);
            }
        }, 'json');
    })
    $(document).on('click','#check-shicai',function () {
        $('.form_shicai').find('.itype').val(1)
        $.post($(".form_shicai").attr('action'), $(".form_shicai").serialize(), function(result){
            if(result.code == 1){
                layer.alert('提交成功。', {icon: 1, yes: function (index) {
                        layer.close(index);
                        window.location.href = result.url;
                    }})
            } else {
                layer.msg(result.msg);
            }
        }, 'json');
    })
    $(document).on('click','#check-shicai-btn',function () {
        $('.form_shicai').find('.itype').val(0)
        $.post($(".form_shicai").attr('action'), $(".form_shicai").serialize(), function(result){
            if(result.code == 1){
                layer.alert('提交成功。', {icon: 1, yes: function (index) {
                        layer.close(index);
                        window.location.href = result.url;
                    }})
            } else {
                layer.msg(result.msg);
            }
        }, 'json');
    })
    $(document).on('click','#check-mb',function () {
        $('.form_mb').find('.itype').val(1)
        $.post($(".form_mb").attr('action'), $(".form_mb").serialize(), function(result){
            if(result.code == 1){
                layer.alert('提交成功。', {icon: 1, yes: function (index) {
                        layer.close(index);
                        window.location.href = result.url;
                    }})
            } else {
                layer.msg(result.msg);
            }
        }, 'json');
    })
    $(document).on('click','#check-mb-btn',function () {
        $('.form_mb').find('.itype').val(0)
        $.post($(".form_mb").attr('action'), $(".form_mb").serialize(), function(result){
            if(result.code == 1){
                layer.alert('提交成功。', {icon: 1, yes: function (index) {
                        layer.close(index);
                        window.location.href = result.url;
                    }})
            } else {
                layer.msg(result.msg);
            }
        }, 'json');
    })
    RCABase.wb_init = init;
})(RCABase)


